from pylab import *
from scipy.interpolate import interp1d

density_main_raw = loadtxt('SN_density_lsst_SNR15_Nfilt3_main_raw.txt')
density_deep_raw = loadtxt('SN_density_lsst_SNR15_Nfilt3_deep_raw.txt')

density_main = interp1d(density_main_raw[:,0],density_main_raw[:,1],kind='cubic')
density_deep = interp1d(density_deep_raw[:,0],density_deep_raw[:,1], kind='cubic')

zmin_main, zmax_main = 0.01, 1.05
zmin_deep, zmax_deep = 0.01, 1.25

z_main = linspace(zmin_main, zmax_main, 100)
z_deep = linspace(zmin_deep, zmax_deep, 100)

n_main = zeros(z_main.shape)
n_deep = zeros(z_deep.shape)

for i in range(len(z_main)):
    n_main[i] = density_main(z_main[i])

for i in range(len(z_deep)):
    n_deep[i] = density_deep(z_deep[i])

savetxt('SN_density_lsst_SNR15_Nfilt3_main.txt', \
        hstack((z_main.reshape(len(z_main),1),n_main.reshape(len(n_main),1))), fmt='%7.4f', delimiter=' ')
savetxt('SN_density_lsst_SNR15_Nfilt3_deep.txt', \
        hstack((z_deep.reshape(len(z_deep),1),n_deep.reshape(len(n_deep),1))), fmt='%7.4f', delimiter=' ')

plot(z_main, n_main, '-or', label='main')
plot(z_deep, n_deep, '-ob', label='deep')

show()
